package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import com.emm.yixun.mobile.model.GetMarketingControlList.BuildingStatusList;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.emm.yixun.mobile.R;

public class BuildingStatusListAdapter extends BaseAdapter {

	Context context;
	ArrayList<BuildingStatusList> list;

	ArrayList<String> l = new java.util.ArrayList<String>();
	ArrayList<String> l2 = new java.util.ArrayList<String>();
	int[] l3 = new int[7];

	private void SetL() {
		l.add("可售");
		l.add("小订");
		l.add("认购");
		l.add("签约");
		l.add("销控");
		l.add("保留");
		l.add("暂不可售");
	}

	private void SetL2() {
		l2.add("#66cc99");
		l2.add("#ff8f57");
		l2.add("#ef4a4a");
		l2.add("#cc66cc");
		l2.add("#bebebe");
		l2.add("#FFFF66");
		l2.add("#888888");
	}

	private void SetL3() {
		l3[0] = R.drawable.building1;
		l3[1] = R.drawable.building2;
		l3[2] = R.drawable.building3;
		l3[3] = R.drawable.building4;
		l3[4] = R.drawable.building5;
		l3[5] = R.drawable.building6;
		l3[6] = R.drawable.building7;
	}

	public BuildingStatusListAdapter(Context context, ArrayList<BuildingStatusList> list) {
		this.context = context;
		this.list = list;
		SetL();
		SetL2();
		SetL3();
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoudlerC v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.buildingstatuslist_item, null);
			v = new ViewHoudlerC();
			v.cb_name = (TextView) convertView.findViewById(R.id.cb_name);
			v.proportionnumber = (TextView) convertView.findViewById(R.id.proportionnumber);
			v.color_textview = (TextView) convertView.findViewById(R.id.color_textview);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlerC) convertView.getTag();
		}
		if (l.get(1).equals(list.get(position).getBuildingStatus()) || "认筹".equals(list.get(position).getBuildingStatus())) {
			v.cb_name.setText("认筹");
		} else {
			v.cb_name.setText(list.get(position).getBuildingStatus());
		}
		if (l.get(0).equals(list.get(position).getBuildingStatus())) {
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(0)));
			v.color_textview.setBackgroundResource(l3[0]);
		} else if (l.get(1).equals(list.get(position).getBuildingStatus()) || "认筹".equals(list.get(position).getBuildingStatus())) {
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(1)));
			v.color_textview.setBackgroundResource(l3[1]);
		} else if (l.get(2).equals(list.get(position).getBuildingStatus())) {
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(2)));
			v.color_textview.setBackgroundResource(l3[2]);
		} else if (l.get(3).equals(list.get(position).getBuildingStatus())) {
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(3)));
			v.color_textview.setBackgroundResource(l3[3]);
		} else if (l.get(4).equals(list.get(position).getBuildingStatus())) {
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(4)));
			v.color_textview.setBackgroundResource(l3[4]);
		} else if (l.get(5).equals(list.get(position).getBuildingStatus())) {
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(5)));
			v.color_textview.setBackgroundResource(l3[5]);
		} else {
			// if (l.get(6).equals(list.get(position).getBuildingStatus()))
			// v.color_textview.setBackgroundColor(Color.parseColor(l2.get(6)));
			v.color_textview.setBackgroundResource(l3[6]);
		}
		v.proportionnumber.setText(list.get(position).getBuildingProportion() + "%");

		return convertView;
	}

	public static class ViewHoudlerC {
		TextView color_textview;
		TextView cb_name;
		TextView proportionnumber;
	}

}
